#include "zmq_client.h"
#include <iomanip>

using std::string; 
using std::vector;

//示例代码功能：使用封装好的sdk获取车辆信息
int main() {
    printf("build_branch:\t%s\nbuild_sha1:\t%s\nbuild_time:\t%s %s\n",
           GIT_BRANCH_NAME, GIT_COMMIT_SHA1, __DATE__, __TIME__);

    std::cout << "test start" << std::endl;
    
    //绑定端口，和ue4通信
    ZmqClient  zmq_client("172.25.176.1", 14552, 40);

    //请求目标数量，可以请求目标数量，车辆数量，障碍物数量; 目标数量就是车辆数量
    //有效输入："Target", "tar", "Vehicle", "veh", "Obstacle", "obs"
    int target_num = zmq_client.request_num("Target");
    std::cout<<"target_num = "<<target_num << std::endl;
    
    //请求目标（或者障碍）具体信息，包括经纬度，高度，速度，index等
    TargetInfo target_info;
    //创建线程不断更新目标具体信息，有效输入例如："Target/1", "tar/1", "Vehicle/1", "veh/1", "Obstacle/1", "obs/1"
    std::thread request_msg(&ZmqClient::request_msg, &zmq_client, "obs/3" , false);
    
    while(true) {
        //如果目标信息更新了，就存到target_info里面
        if (zmq_client.updated(target_info)) {
            std::cout << "target info updated" << std::endl;
            std::cout << std::setprecision(10) << "target_info.lat = "<<target_info.lat << std::endl;
        }
        usleep(50 * 1000);
    }
    request_msg.join();
    return 0;
}